package com.atguigu.gmall.publisher.service.impl;

import com.atguigu.gmall.publisher.mapper.SugarMapper;
import com.atguigu.gmall.publisher.service.SugarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hjy
 * @create 2023/3/22 16:14
 */
@Service
public class SugarServiceImpl implements SugarService {

    @Autowired
    private SugarMapper sugarMapper;

    @Override
    public BigDecimal getGMv(int date) {
        return sugarMapper.getGMV(date);
    }

    @Override
    public Map<String, BigDecimal> getTopN(int date, int limit) {
        HashMap<String, BigDecimal> newMap = new HashMap<>();
        List<Map> topN = sugarMapper.getTopN(date, limit);
        for (Map map : topN) {
            String key = (String) map.get("trademark_name");
            BigDecimal value = (BigDecimal) map.get("total_amount");
            newMap.put(key,value);
        }
        return newMap;

    }
}
